﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Ken_WPF_UI.View
{
    /// <summary>
    /// TabControlWindow.xaml 的交互逻辑
    /// </summary>
    public partial class TabControlWindow : Window
    {
        public TabControlWindow()
        {
            InitializeComponent();
        }


        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            object selectedContent = tabControl1.SelectedContent;
            object selectedItem = tabControl1.SelectedItem;

            //头部内容
            if(selectedItem is TabItem)
            {
                Console.WriteLine($"当前选择tabItem为{(selectedItem as TabItem).Header}");
                //Console.WriteLine($"当前选择tabItem为{(selectedItem as TabItem).Content}");
            }

            //展示内容 或者模板内容
            if(selectedContent is StackPanel)
            {
                StackPanel panel = selectedContent as StackPanel;
                UIElementCollection children = panel.Children;

                StringBuilder sbf = new StringBuilder();

                for (int i = 0; i < children.Count; i++)
                {

                    panel  = children[i] as StackPanel;

                    for (int k = 0; k < panel.Children.Count; k++)
                    {
                        if (panel.Children[k] is Label)
                        {
                            Console.WriteLine($"{(panel.Children[k] as Label).Content}");
                            sbf.Append($"{(panel.Children[k] as Label).Content}");
                        }
                        if (panel.Children[k] is TextBox)
                        {
                            Console.WriteLine($"{(panel.Children[k] as TextBox).Text}\r\n");
                            sbf.Append($"{(panel.Children[k] as TextBox).Text}\r\n");
                        }
                    }
               }

                MessageBox.Show(sbf.ToString());
            }


            
        }
    }
}
